package com.wangcang.widgetlibrary.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import com.wangcang.widgetlibrary.R;
import com.wangcang.widgetlibrary.adapter.ScreenAdapter;
import com.wangcang.widgetlibrary.bean.FilterBean;
import com.wangcang.widgetlibrary.custom_widget.CustomGridView;
import com.wangcang.widgetlibrary.mergeadapter.MergeAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 筛选器
 * Created by ShineF on 2017/7/11 0011.
 */

public class FilterActivity extends AppCompatActivity implements View.OnClickListener {

    private ListView mLvList;
    private CustomGridView mGvThree;
    private CustomGridView mGvTwo;
    private CustomGridView mGvOne;
    private List<FilterBean> mOneList;
    private List<FilterBean> mTwoList;
    private List<FilterBean> mThreeList;
    private View threeView, twoView, oneView;
    private Button mBtnReset;
    private Button mBtnComplete;
    private ScreenAdapter threeAdapter;
    private ScreenAdapter twoAdapter;
    private ScreenAdapter oneAdapter;
    private DrawerLayout mDlLayout;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_filter);
        initView();
    }

    public void initView() {
        mLvList = (ListView) findViewById(R.id.lv_list);
        threeView = View.inflate(this, R.layout.view_filter_three_layout, null);
        mGvThree = (CustomGridView) threeView.findViewById(R.id.gv_three);
        twoView = View.inflate(this, R.layout.view_filter_two_layout, null);
        mGvTwo = (CustomGridView) twoView.findViewById(R.id.gv_two);
        oneView = View.inflate(this, R.layout.view_filter_one_layout, null);
        mGvOne = (CustomGridView) oneView.findViewById(R.id.gv_one);
        mBtnReset = (Button) findViewById(R.id.btn_reset);
        mBtnComplete = (Button) findViewById(R.id.btn_complete);
        mDlLayout = (DrawerLayout) findViewById(R.id.dl_layout);
        mBtnReset.setOnClickListener(this);
        mBtnComplete.setOnClickListener(this);
        initData();
    }

    public void initData() {
        mOneList = new ArrayList<>();
        mTwoList = new ArrayList<>();
        mThreeList = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            mOneList.add(new FilterBean(false, "三个"));
        }
        for (int i = 0; i < 6; i++) {
            mTwoList.add(new FilterBean(false, "两个"));
        }
        for (int i = 0; i < 6; i++) {
            mThreeList.add(new FilterBean(false, "一个"));
        }
        threeAdapter = new ScreenAdapter(1, this, mOneList);
        twoAdapter = new ScreenAdapter(1, this, mTwoList);
        oneAdapter = new ScreenAdapter(1, this, mThreeList);

        mGvThree.setAdapter(threeAdapter);
        mGvTwo.setAdapter(twoAdapter);
        mGvOne.setAdapter(oneAdapter);

        MergeAdapter adapter = new MergeAdapter();
        adapter.addView(threeView);
        adapter.addView(twoView);
        adapter.addView(oneView);
        mLvList.setAdapter(adapter);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_reset:
                List<FilterBean> allList = new ArrayList<>();
                allList.addAll(mOneList);
                allList.addAll(mTwoList);
                allList.addAll(mThreeList);
                for (FilterBean filterBean : allList) {
                    filterBean.setSelect(false);
                }
                threeAdapter.notifyDataSetChanged();
                twoAdapter.notifyDataSetChanged();
                oneAdapter.notifyDataSetChanged();
                break;
            case R.id.btn_complete:
                mDlLayout.closeDrawers();
                break;
        }
    }
}
